<template>
  <div>
    <div class="content">
      <!-- 1.高对比度分辨力---------------------------------------------------------------------------------- -->
      <div id="table1">
        <div class="innertitle" style="position: relative">
          1.高对比度分辨力：<span style="position: absolute; right: 0px;">标准要求 ≥ 5.0lp/cm</span>
        </div>
        <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 100%">
          <tr>
            <td>层厚(mm)</td>
            <td>检测条件</td>
            <td>窗宽</td>
            <td>窗位</td>
            <td>实测结果(lp/cm)</td>
          </tr>
          <tr>
            <td>
              <el-input v-model="form1.thickness" />
            </td>
            <td>
              <el-input class="input-line" v-model="form1.tubeVoltage" />kV、
              <el-input class="input-line" v-model="form1.tubeCurrent" />
              <el-radio v-model="form1.tubeCurrentUnit" :label="0">mA</el-radio>
              <el-radio style="margin-right: 0px;" v-model="form1.tubeCurrentUnit" :label="1">mAs</el-radio>、
              <el-input class="input-line" v-model="form1.exposureTime" />s
            </td>
            <td>
              <el-input v-model="form1.windowWidth" />
            </td>
            <td>
              <el-input v-model="form1.windowLevel" />
            </td>
            <td>
              <el-input v-model="form1.value" />
            </td>
          </tr>
        </table>
      </div>

      <!-- 2.辐射输出量重复性------------------------------------------------------------------------ -->
      <div id="table2">
        <div class="innertitle" style="position: relative">
          2.低对比度分辨力：<span style="position: absolute; right: 0px;">标准要求 ≤ 9.0mm</span>
        </div>
        <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 100%">
          <tr>
            <td rowspan="2">层厚(mm)</td>
            <td rowspan="2">检测条件</td>
            <td rowspan="2">窗宽</td>
            <td rowspan="2">窗位</td>
            <td>标称对比度1.0%细节</td>
          </tr>
          <tr>
            <td>最小细节直径(mm)</td>
          </tr>
          <tr>
            <td>
              <el-input v-model="form2.thickness" />
            </td>
            <td>
              <el-input class="input-line" v-model="form2.tubeVoltage" />kV、
              <el-input class="input-line" v-model="form2.tubeCurrent" />
              <el-radio v-model="form2.tubeCurrentUnit" :label="0">mA</el-radio>
              <el-radio style="margin-right: 0px;" v-model="form2.tubeCurrentUnit" :label="1">mAs</el-radio>、
              <el-input class="input-line" v-model="form2.exposureTime" />s
            </td>
            <td>
              <el-input v-model="form2.windowWidth" />
            </td>
            <td>
              <el-input v-model="form2.windowLevel" />
            </td>
            <td>
              <el-input v-model="form2.value" />
            </td>
          </tr>
        </table>
      </div>

      <!-- 3.KAP指示偏离------------------------------------------------------------------ -->
      <div id="table3">
        <div class="innertitle">
          3.KAP指示偏离（
          <el-checkbox v-model="form3.tool">该设备不显示KAP值</el-checkbox>
          ）（
          <el-radio-group v-model="form3.methodType">
            <el-radio :label="0">KAP仪法</el-radio>
            <el-radio :label="1">剂量仪法</el-radio>
          </el-radio-group>
          ）
        </div>
        <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 100%">
          <tr>
            <td colspan="4">检测条件</td>
            <td colspan="10">检测结果</td>
          </tr>
          <tr>
            <td rowspan="2" width="80px">测试方法</td>
            <td rowspan="2" style="width: 60px;">管电压<br />（kV）</td>
            <td rowspan="2" style="width: 155px;">
              管电流<br />
              （<el-radio v-model="form3.tubeCurrentUnit" :label="0">mA</el-radio>
              <el-radio style="margin-right: 0px;" v-model="form3.tubeCurrentUnit" :label="1">mAs</el-radio>）
            </td>
            <td rowspan="2" width="70px">曝光时间<br />（s）</td>
            <td rowspan="2" width="80px">系统显示值<br />
              <el-radio style="margin-right: 0px;" v-model="form3.displayValueUnit"
                :label="0"><i>$mGy.cm^2$</i></el-radio>
              <el-radio style="margin-right: 0px;" v-model="form3.displayValueUnit"
                :label="1"><i>$μGy.m^2$</i></el-radio>
              <el-radio style="margin-right: 0px;" v-model="form3.displayValueUnit"
                :label="2" v-show="form3.methodType === 0"><i>$Gy.cm^2$</i></el-radio>
              <el-radio style="margin-right: 0px;" v-model="form3.displayValueUnit"
                :label="3" v-show="form3.methodType === 0"><i>$cGy.cm^2$</i></el-radio>
            </td>
            <td colspan="4">
              <el-radio v-model="form3.valueUnit" :label="0"><i>$mGy.cm^2$</i></el-radio>
              <el-radio style="margin-right: 0px;" v-model="form3.valueUnit" :label="1"><i>$μGy.m^2$</i></el-radio>
            </td>
            <td rowspan="2" style="width: 70px;">校准因子<br />K</td>
            <td rowspan="2" style="width: 80px;">校准值</td>
            <td rowspan="2" style="width: 130px;" v-show="form3.methodType == '1'">野照射面积<br />(长×宽)</td>
            <td rowspan="2" width="80px" v-show="form3.methodType == '1'">测量值<br />
              <el-radio style="margin-right: 0px;" v-model="form3.displayValueUnit"
                :label="0"><i>$mGy.cm^2$</i></el-radio>
              <el-radio style="margin-right: 0px;" v-model="form3.displayValueUnit"
                :label="1"><i>$μGy.m^2$</i></el-radio>
            </td>
            <td rowspan="2" style="width: 70px;">指示偏差（%）</td>
          </tr>
          <tr>
            <td colspan="3">测量值</td>
            <td style="width: 80px;">平均值</td>
          </tr>
          <tr v-show="form3.methodType == '0'">
            <td>KAP仪法</td>
            <td><el-input v-model="form3.tubeVoltage_1" @change="(value) => {
              form4.tubeVoltage = value
              form5.tubeVoltage = value
              submitTestForm(4)
              submitTestForm(5)
            }" /></td>
            <td><el-input v-model="form3.tubeCurrent_1" @change="(value) => {
              if (form3.tubeCurrentUnit == 1) { // mAs
                form4.tubeCurrent_MAS = value
                form5.tubeCurrent_MAS = value
              } else {
                form4.tubeCurrent_MA = value
                form5.tubeCurrent_MA = value
              }
              submitTestForm(4)
              submitTestForm(5)
            }" /></td>
            <td><el-input v-model="form3.exposureTime_1" @change="(value) => {
              form4.exposureTime = value
              form5.exposureTime = value
              submitTestForm(4)
              submitTestForm(5)
            }" /></td>
            <td><el-input v-model="form3.displayValue_1" /></td>
            <td><el-input v-model="form3.value_1_1" /></td>
            <td><el-input v-model="form3.value_1_2" /></td>
            <td><el-input v-model="form3.value_1_3" /></td>
            <td class="result"><el-input v-model="form3.average_1" disabled /></td>
            <td class="result"><el-input v-model="form3.calibrationFactor_1" disabled /></td>
            <td class="result"><el-input v-model="form3.calibrationValue_1" disabled /></td>
            <td v-show="form3.methodType == '1'">--</td>
            <td v-show="form3.methodType == '1'">--</td>
            <td class="result"><el-input v-model="form3.deviation_1" disabled /></td>
          </tr>
          <tr v-show="form3.methodType == '1'">
            <td>剂量仪法</td>
            <td><el-input v-model="form3.tubeVoltage_2" @change="(value) => {
              form4.tubeVoltage = value
              form5.tubeVoltage = value
              submitTestForm(4)
              submitTestForm(5)
            }" /></td>
            <td><el-input v-model="form3.tubeCurrent_2" @change="(value) => {
              if (form3.tubeCurrentUnit == 1) { // mAs
                form4.tubeCurrent_MAS = value
                form5.tubeCurrent_MAS = value
              } else {
                form4.tubeCurrent_MA = value
                form5.tubeCurrent_MA = value
              }
              submitTestForm(4)
              submitTestForm(5)
            }" /></td>
            <td><el-input v-model="form3.exposureTime_2" @change="(value) => {
              form4.exposureTime = value
              form5.exposureTime = value
              submitTestForm(4)
              submitTestForm(5)
            }" /></td>
            <td><el-input v-model="form3.displayValue_2" /></td>
            <td><el-input v-model="form3.value_2_1" /></td>
            <td><el-input v-model="form3.value_2_2" /></td>
            <td><el-input v-model="form3.value_2_3" /></td>
            <td class="result"><el-input v-model="form3.average_2" disabled /></td>
            <td class="result"><el-input v-model="form3.calibrationFactor_2" disabled /></td>
            <td class="result"><el-input v-model="form3.calibrationValue_2" disabled /></td>
            <td v-show="form3.methodType == '1'">
              <el-input class="input-line" v-model="form3.irradiatedFieldArea" />
            </td>
            <td v-show="form3.methodType == '1'">
              <el-input v-model="form3.measureValue" />
            </td>
            <td class="result"><el-input v-model="form3.deviation_2" disabled /></td>
          </tr>
        </table>
      </div>

      <!-- 4.图像均匀性------------------------------------------------------------------ -->
      <div id="table4">
        <div class="innertitle">
          4.图像均匀性
          （
          <el-checkbox v-model="form4.tool">该设备无测量工具组</el-checkbox>
          ）
          <div style="font-size: 14px; font-weight: normal; padding-left: 20px;">
            检测条件:
            <el-input v-model="form4.tubeVoltage" class="input-line" />kV，
            <el-input v-model="form4.tubeCurrent_MA" class="input-line" />mA，
            <el-input v-model="form4.exposureTime" class="input-line" />s，
            <el-input v-model="form4.tubeCurrent_MAS" class="input-line" />mAs，
            校准类型：
            <el-button type="primary" size="mini" @click="() => {
              form4.middle_adjusting = form4.middle
              form4.left_up_adjusting = form4.left_up
              form4.right_up_adjusting = form4.right_up
              form4.left_down_adjusting = form4.left_down
              form4.right_down_adjusting = form4.right_down
              submitTestForm(4);
            }">+0</el-button>
            <el-button type="primary" size="mini" @click="() => {
              form4.middle_adjusting = Number((Number(form4.middle) + 1000).toFixed(10))
              form4.left_up_adjusting = Number((Number(form4.left_up) + 1000).toFixed(10))
              form4.right_up_adjusting = Number((Number(form4.right_up) + 1000).toFixed(10))
              form4.left_down_adjusting = Number((Number(form4.left_down) + 1000).toFixed(10))
              form4.right_down_adjusting = Number((Number(form4.right_down) + 1000).toFixed(10))
              submitTestForm(4);
            }">+1000</el-button>
            <el-button type="primary" size="mini" @click="() => {
              form4.middle_adjusting = Number((Number(form4.middle) + 2000).toFixed(10))
              form4.left_up_adjusting = Number((Number(form4.left_up) + 2000).toFixed(10))
              form4.right_up_adjusting = Number((Number(form4.right_up) + 2000).toFixed(10))
              form4.left_down_adjusting = Number((Number(form4.left_down) + 2000).toFixed(10))
              form4.right_down_adjusting = Number((Number(form4.right_down) + 2000).toFixed(10))
              submitTestForm(4);
            }">+2000</el-button>
            <el-button type="primary" size="mini" @click="() => {
              form4.middle_adjusting = Number((Number(form4.middle) + 3000).toFixed(10))
              form4.left_up_adjusting = Number((Number(form4.left_up) + 3000).toFixed(10))
              form4.right_up_adjusting = Number((Number(form4.right_up) + 3000).toFixed(10))
              form4.left_down_adjusting = Number((Number(form4.left_down) + 3000).toFixed(10))
              form4.right_down_adjusting = Number((Number(form4.right_down) + 3000).toFixed(10))
              submitTestForm(4);
            }">+3000</el-button>
          </div>
        </div>
        <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 100%">
          <tr>
            <td>测量位置</td>
            <td>中心</td>
            <td>0点</td>
            <td>3点</td>
            <td>6点</td>
            <td>9点</td>
            <td>结果（%）</td>
          </tr>
          <tr>
            <td style="width: 120px;">实测平均像素值<br />（PV）</td>
            <td><el-input v-model="form4.middle" /></td>
            <td><el-input v-model="form4.left_up" /></td>
            <td><el-input v-model="form4.right_up" /></td>
            <td><el-input v-model="form4.left_down" /></td>
            <td><el-input v-model="form4.right_down" /></td>
            <td class="result" rowspan="3"><el-input v-model="form4.result_adjusting" disabled /></td>
          </tr>
          <tr>
            <td style="width: 120px;">修正值</td>
            <td class="result"><el-input v-model="form4.middle_adjusting" disabled /></td>
            <td class="result"><el-input v-model="form4.left_up_adjusting" disabled /></td>
            <td class="result"><el-input v-model="form4.right_up_adjusting" disabled /></td>
            <td class="result"><el-input v-model="form4.left_down_adjusting" disabled /></td>
            <td class="result"><el-input v-model="form4.right_down_adjusting" disabled /></td>
            <!-- <td class="result"><el-input v-model="form4.result_adjusting" disabled/></td> -->
          </tr>
          <tr>
            <td style="width: 120px;" colspan="2">与中心偏差(%)</td>
            <td class="result"><el-input v-model="form4.deviation_0" disabled /></td>
            <td class="result"><el-input v-model="form4.deviation_3" disabled /></td>
            <td class="result"><el-input v-model="form4.deviation_6" disabled /></td>
            <td class="result"><el-input v-model="form4.deviation_9" disabled /></td>
          </tr>
        </table>
      </div>

      <!-- 5.测距误差------------------------------------------------------------------ -->
      <div id="table5">
        <div class="innertitle">
          5.测距误差
          （
          <el-checkbox v-model="form5.tool" @change="(value) => {
            if (value) {
              form5.readLength_0 = ''
              form5.readLength_90 = ''
            }
          }">该设备无测量工具组</el-checkbox>
          ）
          <span style="font-size: 14px; font-weight: normal;">
            预置条件:
            <el-input v-model="form5.tubeVoltage" class="input-line" />kV，
            <el-input v-model="form5.tubeCurrent_MA" class="input-line" />mA，
            <el-input v-model="form5.exposureTime" class="input-line" />s，
            <el-input v-model="form5.tubeCurrent_MAS" class="input-line" />mAs
          </span>
        </div>
        <table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 100%">
          <tr>
            <td>测量方向</td>
            <td>测量距离<i>$D_m$</i>，mm</td>
            <td>真实距离<i>$D_o$</i>，mm</td>
            <td>偏差E，%</td>
          </tr>
          <tr>
            <td>0°</td>
            <td><el-input v-model="form5.testLength_0" /></td>
            <td><el-input v-model="form5.readLength_0" /></td>
            <td class="result"><el-input v-model="form5.deviation_0" disabled /></td>
          </tr>
          <tr>
            <td>90°</td>
            <td><el-input v-model="form5.testLength_90" /></td>
            <td><el-input v-model="form5.readLength_90" /></td>
            <td class="result"><el-input v-model="form5.deviation_90" disabled /></td>
          </tr>
        </table>
      </div>

      <div id="table9">
        <div class="innertitle">
          其他说明：
        </div>
        <div class="tip-30">
          <el-input type="textarea" placeholder="" v-model="basicForm.specialCircumstances" :autosize="{ minRows: 2 }"
            @blur="$bus.$emit('update-basicinfo', basicForm.taskDetectionEquipmentResultId)"></el-input>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getInfoById, contrastResolutionHigh, contrastResolutionLow,
  kap, imageUniformity, rangeError
} from "@/api/testItem/item17";

export default {
  name: "testItem17",
  data() {
    return {
      form: {},
      // 表单-1.高对比分辨力
      form1: {},
      // 表单-2.低对比分辨力
      form2: {},
      // 表单-3.KAP指示偏离
      form3: {},
      // 表单-4.图像均匀性
      form4: {},
      // 表单-5.测距误差
      form5: {},
      itemsId: null,
    };
  },
  props: {
    // 基本信息数据
    basicForm: {
      type: Object,
      default: () => ({}),
    },
  },
  created() {
    this.$nextTick(() => {
      // 获取详情
      this.getDetailInfo()
      // 绑定请求---表格
      let itemsLength = 5;
      for (let index = 0; index < itemsLength; index++) {
        let tableInputs = document.getElementById(`table${index + 1}`).getElementsByTagName("input");
        for (let i = 0; i < tableInputs.length; i++) {
          this.bind(tableInputs[i], () => {
            this.submitTestForm(index + 1)
          })
        }
      }
    })
  },
  methods: {
    getDetailInfo() {
      getInfoById(this.basicForm.resultId).then(response => {
        this.itemsId = response.data?.itemsId;
        // 1.高对比分辨力
        this.form1 = response.data?.contrastResolutionHigh || {};
        // 2.低对比分辨力
        this.form2 = response.data?.contrastResolutionLow || {};
        // 3.KAP指示偏离
        this.form3 = response.data?.kap || {};
        // 4.图像均匀性
        this.form4 = response.data?.imageUniformity || {};
        // 5.测距误差
        this.form5 = response.data?.rangeError || {};
      }).catch((response) => {
        this.$emit("loadingchange", true);
      });
    },
    // 提交检测项信息
    submitTestForm(index) {
      this.$emit("loadingchange", true);
      this[`form${index}`].itemsId = this.itemsId;
      switch (index) {
        // 1.高对比分辨力
        case 1:
          contrastResolutionHigh(this.form1).then((response) => {
            response.data ? this.form1 = response.data : "";
            this.$emit("loadingchange", false);
            this.getDetailInfo();
          })
          break;
        // 2.低对比分辨力
        case 2:
          contrastResolutionLow(this.form2).then((response) => {
            response.data ? this.form2 = response.data : "";
            this.$emit("loadingchange", false);
          })
          break;
        case 3:
          // 3.KAP指示偏离
          kap(this.form3).then((response) => {
            response.data ? this.form3 = response.data : "";
            this.$emit("loadingchange", false);
          })
          break;
        case 4:
          // 4.图像均匀性
          imageUniformity(this.form4).then((response) => {
            response.data ? this.form4 = response.data : "";
            this.$emit("loadingchange", false);
          })
          break;
        case 5:
          // 5.测距误差
          rangeError(this.form5).then((response) => {
            response.data ? this.form5 = response.data : "";
            this.$emit("loadingchange", false);
          })
          break;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import '../content.scss';
</style>
